/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projectshanghai;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;

/**
 *
 * @author Eric-Standard
 */
public class LoadingPanel extends javax.swing.JPanel implements ActionListener {

    private static final String[] LOADING_STATEMENTS = {"Loading 8-bit images",
        "Calculating gravity", "Testing RAM", "Testing CPU",
        "Setting up points", "Loading physics", "Normalizing vectors",
        "Warning: a bit is trying to escape! Catching bit"};
    private static final int LOADING_STATEMENT_DELAY = 2500;
    private final Timer timer = new Timer(LOADING_STATEMENT_DELAY, this);
    private int prevIndex = -1;

    /**
     * Creates new form LoadingPanel
     */
    public LoadingPanel() {
        initComponents();
        timer.setCoalesce(false);
    }

    public void setValue(int n) {
        jProgressBar1.setValue(n);
    }

    public void setMaximum(int n) {
        jProgressBar1.setMaximum(n);
    }

    public void setMinimum(int n) {
        jProgressBar1.setMinimum(n);
    }

    public void start() {
        timer.start();
    }

    public void done() {
        timer.stop();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Loading...");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(116, 116, 116)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(144, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JProgressBar jProgressBar1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent e) {
        int random = (int) (Math.random() * LOADING_STATEMENTS.length);
        prevIndex = random;
        jLabel1.setText(LOADING_STATEMENTS[random] + "...");
    }
}
